import {AfterViewInit, Component, OnInit} from '@angular/core';
import {DataService} from '../data.service';
import {Router} from '@angular/router';

declare const $: any;
@Component({
  selector: 'app-login',
  templateUrl: './login.component.html',
  styleUrls: ['./login.component.css']
})
export class LoginComponent implements OnInit, AfterViewInit {

  login_message = '账号或密码错误';

  username = '';
  password = '';

  sation_username = '';
  sation_password = '';

  _checked = true;

  user_list = [];

  constructor(private data: DataService, private route: Router) {

  }

  ngOnInit() {

  }

  ngAfterViewInit() {
    console.log($(document).height());
    console.log($(document.body).height());
    console.log(document.body.scrollHeight );
  }

  _console(value) {
    console.log(value);
  }

  submit() {
    if ( this.username == '' || this.password == '' ){
      this.login_message = '账号和密码不能为空';
    } else if (this.username == 'chromie' && this.password == '160522') {
      this.login_message = '验证成功，正在登录';
      this.data.is_login = true;
      if (!$.cookie('sation_username') || !$.cookie('sation_password')){
        $.cookie('sation_username' , 'chromie');
        $.cookie('sation_password' , '160522');
        $.cookie('sation_login' , true);
      }
    }


    this.user_list =  this.data.get_user();
    console.log(this.user_list);
  }

}
